package zhoug.zui.alpha;

import android.content.Context;
import android.util.AttributeSet;

import zhoug.zui.ZUITextView;

import androidx.annotation.AttrRes;
import androidx.annotation.StyleRes;

/**
 * 点击可以改变透明度的文本
 * @Author 35574
 * @Date 2020/7/9
 * @Description
 */
public class ZUIAlphaTextView extends ZUITextView implements IAlphaView {
    private static final String TAG = ">>>ZUIAlphaTextView";
    private AlphaViewHelper _mAlphaViewHelper;

    public ZUIAlphaTextView(Context context) {
        this(context, null);
    }

    public ZUIAlphaTextView(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public ZUIAlphaTextView(Context context, AttributeSet attrs, @AttrRes int defStyleAttr) {
        this(context, attrs, defStyleAttr,0);
    }

    public ZUIAlphaTextView(Context context, AttributeSet attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) {
        super(context, attrs, defStyleAttr);
        init(context, attrs, defStyleAttr,defStyleRes);
    }

    private AlphaViewHelper _getAlphaViewHelper() {
        if (_mAlphaViewHelper == null) {
            _mAlphaViewHelper = new AlphaViewHelper(this);
        }
        return _mAlphaViewHelper;
    }

    private void init(Context context, AttributeSet attrs,  @AttrRes int defStyleAttr, @StyleRes int defStyleRes) {
       AlphaViewHelper.parseTypedArray(_getAlphaViewHelper(),context,attrs,defStyleAttr,defStyleRes);
    }


    @Override
    public void setChangeAlphaWhenPress(boolean changeAlphaWhenPress) {
        _getAlphaViewHelper().setChangeAlphaWhenPress(changeAlphaWhenPress);
    }

    @Override
    public void setChangeAlphaWhenDisable(boolean changeAlphaWhenDisable) {
        _getAlphaViewHelper().setChangeAlphaWhenDisable(changeAlphaWhenDisable);
    }

    @Override
    public void setPressed(boolean pressed) {
        super.setPressed(pressed);
        _getAlphaViewHelper().onPressedChanged(this, pressed);
    }

    @Override
    public void setEnabled(boolean enabled) {
        super.setEnabled(enabled);
        _getAlphaViewHelper().onEnabledChanged(this, enabled);
    }


}
